<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        table {
            width: 500px;
            margin: 100px auto;
            text-align: center;
            border-collapse: collapse;
        }
        
        thead tr {
            height: 40px;
            background-color: #ccc;
        }
        
        td,
        th {
            border: 1px solid #333;
            /* background-color: darkgrey; */
        }
    </style>
</head>

<body>
    <table>
        <thead>
            <tr>
                <th>姓名</th>
                <th>科目</th>
                <th>成绩</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody></tbody>
    </table>
    <!-- 使用对象来存储 -->
    <!-- 先准备数据 -->
    <script>
        var datas = [{
            name: '卫英络',
            subject: 'JavaScript',
            score: 100
        }, {
            name: '红利',
            subject: 'JavaScript',
            score: 98
        }, {
            name: '富恒',
            subject: 'JavaScript',
            score: 99
        }, {
            name: '明玉',
            subject: 'JavaScript',
            score: 88
        }];

        //   在tbody里创建行
        var tbody = document.querySelector('tbody');
        for (i = 0; i < datas.length; i++) {
            var tr = document.createElement('tr');
            tbody.appendChild(tr);
            // 行里创建单元格
            for (var k in datas[i]) {
                var td = document.createElement('td');
                // 把对象的属性值给td
                // k得到属性名,obj[k]得到属性值
                td.innerHTML = datas[i][k];
                tr.appendChild(td);
            }
            var td = document.createElement('td');
            td.innerHTML = ' <a href="javascript:;">删除</a>';
            tr.appendChild(td);
            // var as = document.querySelectorAll('a');
            // as.onclick = function() {
            //         tbody.removeChild(this.parentNode.par);
            //     }

        }
        var as = document.querySelectorAll('a');
        for (i = 0; i < as.length; i++) {
            as[i].onclick = function() {
                //    node.removeChild(child)
                tbody.removeChild(this.parentNode.parentNode);
            }
        }
    </script>
</body>

</html>